package com.itbaizhan.shopping_common.exception;

import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.result.BusException;
import com.itbaizhan.shopping_common.result.CodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

// 统一异常处理器
@RestControllerAdvice
public class GlobalExceptionHandler {
	//处理业务异常
	@ExceptionHandler(BusException.class)
	public BaseResult defaultExceptionHandler(BusException e) {
		return new BaseResult(e.getCode(), e.getMsg(), null);
	}
	//处理系统异常
	@ExceptionHandler(Exception.class)
	public BaseResult defaultExceptionHandler(Exception e) {
		e.printStackTrace();
		return new BaseResult(CodeEnum.SYSTEM_ERROR.getCode(), CodeEnum.SYSTEM_ERROR.getMessage(), null);
	}
}
